<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../config.inc.php");

$_LangPath = "betnowlist";
include_once(__Member_Path."/logincheck.php");
include_once(__Language_Path."/selectlanguage_member.php");
include_once(__Modules_Path."/ChangeTime.lib.php");
include_once(__Modules_Path."/WagerForm.lib.php");
include_once(__Common_Path."/Lotto.inc.php");
include_once(__Modules_Path."/Lotto.lib.php");
/*if(file_exists(__Root_Path."/tmp/lock.countResult")){
	$GLOBALS["errormessage"] = $_strBetNowList["onCountResult"];//"結帳中，請稍後！！";
	include_once(__Root_Path."/error.php");
	exit();
}*/

$strSQL = "select a.ID, a.LottoID, b.BetDate, a.Number as Number, b.BetTime, a.Bet_Type, b.Content, a.MemStake, a.MemCommission, a.MemPayOff, a.LottoID, a.isPayOff, b.OneStake from `bet_BetListTmp` a, `bet_BetListContent` b where a.PayupDate >= CURRENT_DATE() and a.MemID = ".$_SESSION["Member_Info"] -> ID." and a.ID = b.ID order by a.LottoID, a.ID desc";//a.isPayOff = 0 and 
if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Error";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}
$arrRows = array();
if(mysql_num_rows($RS) > 0){
	while($Rows = mysql_fetch_object($RS)){
		$arrRows[$Rows -> LottoID][] = $Rows;
	}
}
@mysql_free_result($RS);

$fp = @file(__Membertemplate_Path."/betnow_list.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
$fp = str_replace("{Name}", $_SESSION["Member_Info"] -> Name, $fp);
$GD = DateForm(date("Y-m-d"), date("H:i:s"), "Y-m-d");
$GT = TimeForm(date("Y-m-d"), date("H:i:s"), "H:i:s");
$fp = str_replace("{BetDate}", $GD." ".$GT, $fp);

//以下位置不可上下移動
while(list($k, $v) = each($_strBetNowList)){
	$fp = str_replace("{".$k."}", $v, $fp);
}

preg_match("/<!--@ LottoContent Start @\/\/-->(.+)<!--@ LottoContent End @\/\/-->/s", $fp, $d);
$LottoContent = $d[1];
preg_match("/<!--@ BetContent While Start @\/\/-->(.+)<!--@ BetContent While End @\/\/-->/s", $LottoContent, $d);
$BetContent = $d[1];

//While Start
$All = 0;  //總筆數
$AllStake = 0;  //總下注金額
$AllPayOff = 0;  //總最高可得派彩
$AllComm = 0;  //總退水

$arrLottoPower = getLottoUsePowerArray();
$arrOneStake[1] = array(7, 8, 9, 10, 11, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43);
$arrOneStake[2] = array();
$arrOneStake[3] = array();
$arrOneStake[4] = array(15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35);
foreach($_arrLotto as $intLID => $arrL){
	if(!in_array($intLID, $arrLottoPower))continue;

	$total = 0;
	$totalStake = 0;
	$totalPayOff = 0;
	$totalComm = 0;
	$strWCon = "";
	if(sizeof($arrRows[$intLID]) > 0){
		foreach($arrRows[$intLID] as $Rows){

			$strTmp = "";
			$tmpBetContent = str_replace("{BetID}", $Rows -> ID, $BetContent);
			$strTmpCon =  WagerFormTrans($Rows -> LottoID, $Rows -> Bet_Type, $Rows -> Content);
			$flComm = round($Rows -> MemStake*$Rows -> MemCommission, 2);
			if($Rows -> isPayOff >= 0){
				$total++;
				$totalStake += $Rows -> MemStake;
				$totalPayOff += $Rows -> MemPayOff;
				$totalComm += $flComm;
				$tempMemPayOff = (int) ($Rows -> MemPayOff);
				//$tmpBetContent = str_replace("{MemPayOff}", $tempMemPayOff, $tmpBetContent);
				$strCancel = "";
			}else{
				//$tmpBetContent = str_replace("{MemPayOff}", $_strBetNowList["Cancel"], $tmpBetContent);
				$strCancel = "<a style='color: #FF0000;'>".$_strBetNowList["Cancel"]."</a>&nbsp;&nbsp;";
			}
			//if($arrL["LType"] == 1 && $Rows -> Bet_Type >= 7 && $Rows -> Bet_Type <= 11 && !empty($Rows -> OneStake)){
			if(in_array($Rows -> Bet_Type, $arrOneStake[$arrL["LType"]]) && !empty($Rows -> OneStake)){
				$WagerNo = round($Rows -> MemStake / $Rows -> OneStake);
				if($WagerNo > 1){
					$strTmp = '<span class="WagerCon_WagerNo_color">'.$Rows -> OneStake.' x '.$WagerNo.'</span><br /><br />';
				}
			}
			$tmpBetContent = str_replace("{MemStake}", $strTmp.$strCancel.$Rows -> MemStake, $tmpBetContent);
			$tmpBetContent = str_replace("{MemComm}", $flComm, $tmpBetContent);
			$tmpBetContent = str_replace("{Content}", $strTmpCon, $tmpBetContent);
			$tmpBetContent = str_replace("{Lotto}", $_arrLotto[$Rows -> LottoID]["Lotto_".$_intLang], $tmpBetContent);
			$GD = DateForm($Rows -> BetDate, $Rows -> BetTime);
			$GT = TimeForm($Rows -> BetDate, $Rows -> BetTime, "H:i:s");
			$tmpBetContent = str_replace("{BetTime}", $GD." ".$GT, $tmpBetContent);
			if($arrL["LType"] == 1 && $Rows -> Bet_Type == 15){
				$tmpBetContent = str_replace("{MemBetType}", $_arrBet_Type[$arrL["LType"]][$Rows -> Bet_Type]."<br />".$Rows -> Number.$_strSame_String[Connection]."1", $tmpBetContent);
			}else{
				$tmpBetContent = str_replace("{MemBetType}", $_arrBet_Type[$arrL["LType"]][$Rows -> Bet_Type], $tmpBetContent);
			}
			$strWCon .= $tmpBetContent;
		} //foreach($arrRows[$intLID] as $Rows)
	} //if(sizeof($arrRows[$intLID]) > 0)
	$All += $total;
	$AllStake += $totalStake;
	$AllPayOff += $totalPayOff;
	$AllComm += $totalComm;

	$tmpLottoContent = str_replace("{LottoName}", $arrL["Lotto_".$_intLang], $LottoContent);
	$tmpLottoContent = preg_replace("/<!--@ BetContent While Start @\/\/-->.+<!--@ BetContent While End @\/\/-->/s", $strWCon, $tmpLottoContent);
	$tmpLottoContent = str_replace("{TotalNo}", $total, $tmpLottoContent);
	$tmpLottoContent = str_replace("{TotalStake}", $totalStake, $tmpLottoContent);
	$tmpLottoContent = str_replace("{TotalPayOff}", $totalPayOff, $tmpLottoContent);
	$tmpLottoContent = str_replace("{TotalComm}", $totalComm, $tmpLottoContent);
	$strLCon .= $tmpLottoContent;
} //foreach($_arrLotto as $intLID => $arrL)

$fp = preg_replace("/<!--@ LottoContent Start @\/\/-->.+<!--@ LottoContent End @\/\/-->/s", $strLCon, $fp);
$fp = str_replace("{AllTotalNo}", $All, $fp);
$fp = str_replace("{AllTotalStake}", $AllStake, $fp);
$fp = str_replace("{AllTotalPayOff}", $AllPayOff, $fp);
$fp = str_replace("{AllTotalComm}", $AllComm, $fp);

//輸出
WebOutputHTML($fp, 1);
?>